<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class ArtlContentsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function GetIndex()
    {
        echo 22;
    }


    //显示文章详细内容
    public  function getShow($id,$ids)
    {
        //获取全部子分类
        $cates = self::pullCates(self::pullType(),0);
        $datas = self::pullCates(self::pullType(),0);
       // var_dump($cates);
        //获取一级分类
        $type = DB::table('type')->where('pid',0)->get();

        //获取id的信息
        $mess = DB::table('type')->where('id',$ids)->first();

        // dd($cates);
        //获取配置信息
        $config = DB::table('config')->first();

        //友情链接
        $blinks = DB::table('blink')->get();

        //获取文章内容
        $page = DB::table('article')->where('uid',$ids)->paginate(3);

        //获取文章详细内容
        $cont = DB::table('article')->where('id',$id)->first();

        //返回模板
        return view('Home.article.show',['mess'=>$mess,'cates'=>$cates,'config'=>$config,'blinks'=>$blinks,'type'=>$type,'datas'=>$datas,'page'=>$page,'cont'=>$cont]);
        
    }


    //获取全部分类
    public  static function pullType()
    {
        return DB::table('type')->get();
    }

    //获取全部下级分类的
    public static function pullCates($sort,$pid)
    {
        $data = [];
        foreach($sort as $k=>$v)
        {
            if($v->pid == $pid){

                $v->sub = self::pullCates($sort,$v->id);
                $data[]=$v;
            }
        }
        return $data;
    }
    
}
